import pygame
from settings import Settings
from ship import Ship
import game_funcitons as gf
from game_stats import GameStats
from pygame.sprite import Group
from button import Button
from ScoreBoard import ScoreBoard
def run_game():
    """游戏运行函数"""
    # 初始化并创建一个屏幕对象
    pygame.init()
    # 获取游戏的初始化设置函数
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    ship = Ship(settings, screen)
    pygame.display.set_caption('外星人游戏')
    # 创建一个存储子弹的编组
    bullets = Group()
    aliens = Group()
    gf.create_fleet(settings, screen, aliens, ship)
    # 创建游戏的统计信息
    stats = GameStats(settings)
    # 创建paly按钮
    play_button = Button(settings, screen, 'play')
    # 创建记分牌
    sb = ScoreBoard(settings, screen, stats)
    # 开始游戏的主循环
    while True:
        # 监听鼠标和键盘的事件
        gf.check_event(settings, screen, ship, bullets, stats, play_button, aliens, sb)
        if stats.game_active:
            # 移动对应的图像位置
            ship.update()
            gf.bullets_update(settings, screen, ship, aliens, bullets, sb, stats)
            gf.alien_update(settings, ship, aliens, stats, screen, bullets, sb)
        # 刷新页面显示
        gf.update_screen(settings, screen, ship, bullets, aliens, stats, play_button, sb)


run_game()
